#include <cstdio>
#include <vector>
#include <time.h>

template <typename T>
void swap(T &elem1, T &elem2)
{
    T buff = elem2;
    elem2 = elem1;
    elem1 = buff;
}

std::vector<int> bubble_sort(std::vector<int> arr)
{
    int n = arr.size() - 1;
    bool swapped;

    for (int i = 0; i < n; i++) 
    {
        for (int j = 0; j < n - i; j++) 
        {
            if (arr[j] > arr[j + 1]) swap(arr[j], arr[j + 1]); 
        }
    }
            
    return arr;
}

void run(const char * fname, int nums)
{
    clock_t start, end;

    auto f = fopen(fname, "r");

    std::vector<int> arr(nums, nums);

    for (auto &el : arr) fscanf(f, "%d", &el);

    start = clock();
    arr = bubble_sort(arr);
    end = clock();
    printf("%.9f\n", ((double) (end - start)) / CLOCKS_PER_SEC);
}

int main()
{
    run("m1_sorted.txt", 5000);
    run("m2_reverse.txt", 5000);
    run("m3_shuffle.txt", 5000);

    return 0;
}